﻿@model cloudscribe.Core.IdentityServerIntegration.Models.ApiEditViewModel
@using cloudscribe.Core.IdentityServerIntegration
@using Microsoft.Extensions.Localization
@inject IStringLocalizer<CloudscribeIds4Resources> sr
@{
    var secretIndex = 0;
}
@if (Model.CurrentApi != null)
{
    <div class="col-md-offset-2 col-md-10">
        <h3>@sr["Secrets"] </h3>
        @{ await Html.RenderPartialAsync("AddApiSecretPartial", Model.NewApiSecret);}
        @if (Model.CurrentApi.ApiSecrets.Count > 0)
        {
            <table class="table table-striped">
                <tr>
                    <th></th>
                    <th>
                        @sr["Value"]
                    </th>
                    <th>
                        @sr["Description"]
                    </th>
                    <th>
                        @sr["Expiration"]
                    </th>
                    <th>
                        @sr["Type"]
                    </th>
                </tr>
                @foreach (var c in Model.CurrentApi.ApiSecrets)
                {
                    <tr>
                        <td>
                            <button type="button" class="btn btn-danger btn-xs" data-toggle="modal" data-target="@("#confirmDeleteSecretModal" + secretIndex)">
                                @sr["Delete"]
                            </button>
                            <form asp-controller="ApiResource" asp-action="DeleteApiSecret">
                                <input asp-for="SiteId" type="hidden" />
                                <input name="ApiName" value="@Model.CurrentApi.Name" type="hidden" />
                                <input name="SecretValue" value="@c.Value" type="hidden" />
                                <div class="modal fade" id="@("confirmDeleteSecretModal" + secretIndex)" tabindex="-1" role="dialog" aria-labelledby="@("confirmDeleteSecretHeading" + secretIndex)">
                                    <div class="modal-dialog modal-sm" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal" aria-label='@sr["Close"]'><span aria-hidden="true">&times;</span></button>
                                                <h4 class="modal-title" id="@("confirmDeleteSecretHeading" + secretIndex)">@sr["Confirm Delete"]</h4>
                                            </div>
                                            <div class="modal-body">
                                                @string.Format(sr["Are you sure you want to delete the secret {0}?"], c.Value)
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">@sr["Cancel"]</button>
                                                <input type="submit" value='@sr["Delete"]' class="btn btn-danger btn-ok" />
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </td>
                        <td>@c.Value</td>
                        <td>@c.Description</td>
                        <td>@Html.DisplayFor(modelItem => c.Expiration)</td>
                        <td>@c.Type</td>
                    </tr>
                    {
                        secretIndex += 1;
                    }
                }
            </table>
        }
    </div>

}
